package cn.player.adapter;

import android.content.Context;
import android.widget.ImageView;

import net.tsz.afinal.FinalBitmap;

import java.util.List;

import cn.player.R;
import cn.player.App;
import cn.player.entity.ChannelInfo;
import cntv.player.core.util.Utils;
import cntv.player.engine.Const;
import cn.player.media.adapter.BaseAdpt;

/**
 * 右侧频道信息adapter
 * @author zengliang
 *
 */
public class RightChannelInfoAdapter extends BaseAdpt<ChannelInfo> {
	

	private App app;
	private FinalBitmap finalBitamp;

	public RightChannelInfoAdapter(Context mContext, List<ChannelInfo> mData,int layoutResource) {
		super(mContext, mData, layoutResource);
		// TODO Auto-generated constructor stub
		app = (App) mContext.getApplicationContext();
		finalBitamp = app.getFinalBitmap();
	}

	@Override
	protected void addViewId() {
		// TODO Auto-generated method stub
		mViewIds.add(R.id.iv_right_channel_image);
		mViewIds.add(R.id.iv_right_channel_icon);
	}

	@Override
	protected void updateItemViews(int position) {
		// TODO Auto-generated method stub
		ImageView iv_channel_img = (ImageView) viewHolder.getView(R.id.iv_right_channel_image);
		ImageView iv_channel_icon = (ImageView) viewHolder.getView(R.id.iv_right_channel_icon);
		
		ChannelInfo info = mData.get(position);
		if(Utils.strToLong(info.getAutoImg()) == 1){
			String autoImgUrl = app.getBaseUrls().get(Const.KEY_AUTOIMG_URL).getUrl() + info.getChannelId() + "_01.png" + "?rdm=null";
			finalBitamp.display(iv_channel_img, autoImgUrl);
		}else{
			finalBitamp.display(iv_channel_img, info.getImgUrl());
		}
		finalBitamp.display(iv_channel_icon, info.getChannelImg());
	}

}
